package com.example.mall.web.controller;

import com.example.mall.domain.PayOrder;
import com.example.mall.dto.PayOrderDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.PayOrderQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IPayOrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/payOrder")
public class PayOrderController {

    @Autowired
    public IPayOrderService payOrderService;

    /**
     * 分页查询支付订单表信息
     * @param payOrderQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询支付订单表信息",notes = "分页查询支付订单表信息",httpMethod = "GET")
    public JSONResult queryPage(PayOrderQuery payOrderQuery){
        PageDTO<PayOrderDto> payOrderDtoPageDTO = payOrderService.queryPage(payOrderQuery);
        return JSONResult.success("查询成功",payOrderDtoPageDTO);
    }

    /**
     * 根据id查询支付订单表信息
     * @param id
     * @return
     */
    @GetMapping("query/{id}")
    @ApiOperation(value = "根据id查询支付订单表信息",notes = "根据id查询支付订单表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.PAY_ORDER_NOT_ID);
        }
        PayOrder payOrder = payOrderService.getById(id);
        return JSONResult.success("查询成功",payOrder);
    }

    /**
     * 根据id查询支付订单表信息
     * @param id
     * @return
     */
    @GetMapping("queryPayOrderById/{id}")
    @ApiOperation(value = "根据id查询支付订单表信息",notes = "根据id查询支付订单表信息",httpMethod = "GET")
    public JSONResult queryPayOrderById(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.PAY_ORDER_NOT_ID);
        }
        PayOrder payOrder = payOrderService.queryPayOrderById(id);
        return JSONResult.success("查询成功",payOrder);
    }

    /**
     * 查询全部支付订单表信息
     * @param
     * @return
     */
    @GetMapping("queryPayOrderList")
    @ApiOperation(value = "查询全部支付订单表信息",notes = "查询全部支付订单表信息",httpMethod = "GET")
    public JSONResult queryPayOrderList(){
        List<PayOrder> payOrders = payOrderService.queryPayOrderList();
        return JSONResult.success("查询成功",payOrders);
    }

    /**
     * 新增支付订单表
     * @param payOrderDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增支付订单表",notes = "新增支付订单表",httpMethod = "POST")
    public JSONResult insert(@RequestBody PayOrderDto payOrderDto){
        payOrderService.insert(payOrderDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改支付订单表信息
     * @param payOrderDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改支付订单表信息",notes = "修改支付订单表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody PayOrderDto payOrderDto){
        payOrderService.update(payOrderDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除支付订单表信息
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除支付订单表信息",notes = "删除支付订单表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activitiesProductId") Long id) {
        payOrderService.delete(id);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除支付订单表信息
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除支付订单表信息",notes = "批量删除支付订单表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ids) {
        payOrderService.deleteBatch(ids);
        return JSONResult.success("批量删除成功");
    }
}
